package hellfire.platform.input;

import hellfire.game.Chicken;
import hellfire.game.Game;
import hellfire.system.graphics.GLRenderer;
import hellfire.system.graphics.GLVec2;
import android.util.Log;
import android.view.MotionEvent;

public class GameListener implements TouchListener 
{
	private Game game;
	private GLVec2 scale, translate;
	
	public GameListener(Game game, GLVec2 scale, GLVec2 translate)
	{
		this.game = game;
		this.scale = new GLVec2(1/scale.x(), 1/scale.y());
		this.translate = translate.neg();
	}
	
	public void onTouchEvent(MotionEvent e, GLVec2 pos) 
	{
		if(e.getAction() != MotionEvent.ACTION_DOWN)
			return;
		Chicken c;
		pos = pos.mul(scale);
		pos = pos.add(translate);
		if(	pos.x() > GLRenderer.ASP || pos.x() < -GLRenderer.ASP ||
			pos.y() > 1 || pos.y() < -1) 
			return; // outside of game canvas
		while((c = (Chicken) game.getObjectAtPoint(pos, Chicken.class, Chicken.getBoxDim().x())) != null)
		{
			c.Explode();
		}
	}

	@Override
	public boolean testPosition(GLVec2 pos) 
	{
		return true;
	}

}
